<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta name="author" content="中文Lee 360811363@qq.com">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="author" content="lizhongwen@lizhongwen.com">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
    <link rel="stylesheet" href="../../../lib/ext/css/bootstrapStyle/bootstrapStyle.css" type="text/css">
    <!--
    * [LupMisNotAllowedSync]
    * 本代码为系统自动生成代码，请根据自己业务进行修改;
    * 生成时间 2022-02-15 18:29:17;
    * 版权所有 2020-2022 lizhongwen，并保留所有权利;
    * 说明: 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；不允许对程序代码以任何形式任何目的的再发布;
    * 作者: 中文Lee;
    * 作者主页: http://www.lizhongwen.com;
    * 邮箱: 360811363@qq.com;
    * QQ: 360811363;
    -->
    <style type="text/css">
        .node_name input {
            padding: 5px;
        }
        
        .ztree li span {
            max-width: 240px;
        }
        
        .layui-form-select input {
            padding-left: 20px;
        }
        
        .multi dl dd.layui-this {
            background-color: #fff
        }
    </style>

</head>

<body style="overflow-y:hidden">
    <div class="layui-card layui-anim">

        <div class="layui-card-body">
            <div class="layui-row">
                <button type="button" class="layui-btn layui-btn-warm layui-btn-sm" onclick="treeDemoObj.expandAll(true)">全部展开</button>
                <button type="button" class="layui-btn layui-btn-danger layui-btn-sm" onclick="treeDemoObj.expandAll(false)">全部收缩</button>

                <button type="button" class="layui-btn layui-btn-sm" onclick="selectDo()">确定选择</button>
                <input type="hidden" id="org_id" value="">
                <input type="hidden" id="org_name" value="">

            </div>
            <div class="layui-row">
                <hr>
            </div>
            <div class="layui-row  layui-form-item" style="display: -webkit-flex;display: flex;">
                <div id="treeDemo" class="ztree" style="overflow-y: auto;width: 100%;">

                </div>

            </div>
        </div>
    </div>
    <script src="../../../js/run.js"></script>
    <script type="text/javascript" src="../../../lib/ext/js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="../../../lib/ext/js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="../../../lib/ext/js/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="../../../lib/ext/js/jquery.ztree.exedit.js"></script>
    <script type="text/javascript">
        //这里引用一下，否则不生效

        $(document).ajaxSend(function(event, jqxhr, settings) {
            jqxhr.setRequestHeader("accessuid", localStorage.getItem("accessuid"));
            jqxhr.setRequestHeader("accesstoken", localStorage.getItem("accesstoken"));
        });
        var accessuid = localStorage.getItem("accessuid");
        var accesstoken = localStorage.getItem("accesstoken");
        var setting = {
            async: {
                enable: true,
                contentType: "application/json",
                headers: {
                    'accessuid': accessuid,
                    'accesstoken': accesstoken
                },
                type: "post",
                dataType: "json",
                autoParam: ["id", "name"],
                url: base_gateway + "sys/org/lists"
            },
            view: {
                expandSpeed: "1",
                showLine: true,
                showIcon: true,
                showTitle: true,
                selectedMulti: false
            },
            edit: {
                enable: false
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                onClick: onClick,
                onAsyncSuccess: zTreeOnAsyncSuccess, // 异步加载正常结束的事件回调函数
            }
        };

        //用于捕获异步加载正常结束的事件回调函数
        function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
            var treeObj = $.fn.zTree.getZTreeObj(treeId);
            var nodes = treeObj.getNodes();
            //默认展开前3个
            treeObj.expandAll(true);
            for (var i = 0; i < nodes.length; i++) {
                // treeObj.expandNode(nodes[i], true, false, false); //默认展开第一级节点
            }

        }
        //目录点击事件
        function onClick(event, treeId, treeNode, clickFlag) {
            $("#org_id").val(treeNode.id);
            $("#org_name").val(treeNode.name);
            // parent.doSelect(treeNode.id, treeNode.name);
        }

        var treeDemoObj;
        $(function() {
            treeDemoObj = $.fn.zTree.init($("#treeDemo"), setting);
            var windowH = $(window).height();
            if (windowH <= 300) {
                windowH = 300;
            }

            $("#treeDemo").css("height", (windowH - 135) + "px");
            $(window).resize(function() { //当浏览器大小变化时
                var windowH = $(window).height();
                if (windowH <= 300) {
                    windowH = 300;
                }

                $("#treeDemo").css("height", (windowH - 135) + "px");
            });
        });

        function selectDo() {
            var orgId = $("#org_id").val();
            var orgName = $("#org_name").val();
            if (orgId == "") {
                layer.msg("请选择一个机构");
                return false;
            }
            parent.doSelect(orgId, orgName);
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        }
    </script>
</body>

</html>